import Vue from 'vue'

const NumConstructor = Vue.extend(require('./popNum.vue'))

const instance = new NumConstructor({
  el: document.createElement('div')
})
NumConstructor.prototype.close = function () {
  const el = instance.$el
  el.parentNode && el.parentNode.removeChild(el)
}
NumConstructor.prototype.closeNum = function (stay, num, callback) {
  typeof callback === 'function' && callback(num)

  if (stay) {
    return
  }

  const el = instance.$el
  instance.mes = ''
  instance.num = 0
  instance.maxNum = 0
  instance.minNum = 0
  instance.opts = []
  instance.flag = false
  el.parentNode && el.parentNode.removeChild(el)
}
const PopNum = (options = {}) => {
  instance.num = options.num || 0
  instance.maxNum = options.maxNum
  instance.minNum = options.minNum
  instance.opts = options.opts
  instance.flag = options.flag || false
  instance.mes = options.mes
  document.body.appendChild(instance.$el)
  // 添加自动聚焦
  instance.$refs.numInput.focus()
}

export default {
  close: instance.close,
  PopNum
}
